/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bs.global.web;

import bs.global.modelo.Comprobante;
import bs.global.rn.ComprobanteRN;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

/**
 *
 * @author ctrosch
 */
@ManagedBean (name="conversoresGeneral")
@SessionScoped
public class ConversoresGeneral {

    @EJB private ComprobanteRN comprobanteRN;
    


    /** Creates a new instance of ConversoresBean */
    public ConversoresGeneral() {
        
    }

    public Converter getComprobante() {
        return new Converter() {

            @Override
            public Object getAsObject(FacesContext context, UIComponent component, String value) {
                if (value.trim().equals("") || value == null) {
                    return null;
                }

                String a[] = value.split(",");
                String modcom[] = a[0].split("=");
                String codcom[] = a[1].split("=");


                Comprobante c = comprobanteRN.getComprobante(modcom[1], codcom[1]);
                return c;
            }

            @Override
            public String getAsString(FacesContext context, UIComponent component, Object value) {
                if (value == null || value.equals("")) {
                    return "";
                } else {

                    return ((Comprobante) value).getIdPK() + "";
                }
            }
        };
    }

    
}
